//
//  HomeModel.swift
//  DadaSolusi
//
//  Created by liyahao on 2025/9/9.
//

import UIKit

struct HomeModel: JSONable {
    var sacrdiscusseur: Sacrdiscusseur?
    var sanctitive: [Sanctitive]?
    var homoienne: [Homoienne]?
}

// MARK: - Sacrdiscusseur
struct Sacrdiscusseur: Codable {
    var requireoon: String?
    var stillress: String?
}

// MARK: - Sanctitive
struct Sanctitive: Codable {
    var cidia: String?
    var taloery: Taloery?
}

// MARK: - Taloery Enum
// Because 'taloery' can be an array or a single object, we need to use an enum with associated values.
// This is a common pattern for handling mixed types in Codable.
enum Taloery: Codable {
    case largeCard(LargeCard)
    case smallCard(SmallCard)
    case repayArray([Repay])
    case productListArray([ProductList])
    case bannerArray([Banner])

    init(from decoder: Decoder) throws {
        var container = try decoder.singleValueContainer()
        if var value = try? container.decode([Banner].self) {
            self = .bannerArray(value)
            return
        }
        if var value = try? container.decode(LargeCard.self) {
            self = .largeCard(value)
            return
        }
        if var value = try? container.decode(SmallCard.self) {
            self = .smallCard(value)
            return
        }
        if var value = try? container.decode([Repay].self) {
            self = .repayArray(value)
            return
        }
        if var value = try? container.decode([ProductList].self) {
            self = .productListArray(value)
            return
        }
        throw DecodingError.typeMismatch(Taloery.self, DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "Wrong type for Taloery"))
    }
    
    func encode(to encoder: Encoder) throws {
        var container = encoder.singleValueContainer()
        switch self {
        case .bannerArray(var value):
            try container.encode(value)
        case .largeCard(var value):
            try container.encode(value)
        case .smallCard(var value):
            try container.encode(value)
        case .repayArray(var value):
            try container.encode(value)
        case .productListArray(var value):
            try container.encode(value)
        }
    }
}

// MARK: - Banner
struct Banner: Codable {
    var noteence: String?
    var internationalose: String?
}

// MARK: - LargeCard
struct LargeCard: Codable {
    var dayit: Int?
    var maximmessagekin: String?
    var rarite: String?
    var clusic: String?
    var ornithoo: String?
    var dipsation: String?
    var unit: String?
    var moveress: String?
    var discussionization: String?
    var nautish: String?
    var locutfic: String?
    var gram: String?
}

// MARK: - SmallCard
// This has the same structure as LargeCard
typealias SmallCard = LargeCard

// MARK: - Repay
struct Repay: Codable {
    var pict: String?
    var caesphonery: String?
    var herbive: String?
    var noteence: String?
}

// MARK: - ProductList
struct ProductList: Codable {
    var dayit: Int?
    var maximmessagekin: String?
    var ornithoo: String?
    var dipsation: String?
    var unit: String?
    var mightster: String?
    var nautish: String?
    var clusic: String?
    var vulsfootan: [String]?
    var morphacy: String?
    var rarite: String?
    var relationshiptic: String?
    var create: String?
    var mitast: Int?
    var causing: String?
    var available: String?
    var provaration: Int?
    var soliter: String?
    var noteence: String?
    var bromoaneity: Int?
    var thereule: [String]?
    var lavuous: String?
    var tellurial: [String]?
    var dolorion: Int?
    var million: String?
    var discussionization: String?
}

// MARK: - Homoienne
struct Homoienne: Codable {
    var serp: String?
    var herbive: String?
    var boyy: String?
}
